﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using HealthManagement.Data.Model;
using HealthManagement.Model;
using com.jwxcd.CommunityDriver;
using Telerik.Windows.Controls;
using HealthManagement.Data.Service;
using Telerik.Windows.Controls.BulletGraph;
using System.Threading;
using PM.Controls.Common;

namespace HealthManagement.View
{
    /// <summary>
    /// MeterPanel.xaml 的交互逻辑
    /// </summary>
    public partial class MeterPanel : MeasureBase
    {
        //阀值
        RefValue refval;

        public MeterPanel()
        {
            InitializeComponent();

            initMeasureType();

            this.Loaded += new RoutedEventHandler(MeterPanel_Loaded);
            this.Unloaded += new RoutedEventHandler(MeterPanel_Unloaded);

            if (Application.Current.Properties["selectedUser"] != null)
            {
                appearance.DataContext = Application.Current.Properties["selectedUser"];
            }
            else
            {
                MessageBox.Show("没有选择用户");
            }

            #region 绑定阀值
            HealthDataRefService ser = new HealthDataRefService();

            string userId = (Application.Current.Properties["selectedUser"] as UserModel).UserId;

            refval = ser.GetRef(userId);

            int minimum = (int)(refval.SBP.min * 0.7);
            int maximum = (int)(refval.SBP.max * 1.3);
            SBP2.Minimum = minimum;
            SBP2.Maximum = maximum;
            SBP2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("actual") as Brush, Value = refval.SBP.min });
            SBP2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("components") as Brush, Value = refval.SBP.max });
            SBP2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("under") as Brush, Value = maximum });

            minimum = (int)(refval.DBP.min * 0.7);
            maximum = (int)(refval.DBP.max * 1.3);
            DBP2.Minimum = minimum;
            DBP2.Maximum = maximum;
            DBP2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("actual") as Brush, Value = refval.DBP.min });
            DBP2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("components") as Brush, Value = refval.DBP.max });
            DBP2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("under") as Brush, Value = maximum });

            minimum = (int)(refval.HR_Value.min * 0.7);
            maximum = (int)(refval.HR_Value.max * 1.3);
            HR_value2.Minimum = minimum;
            HR_value2.Maximum = maximum;
            HR_value2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("actual") as Brush, Value = refval.HR_Value.min });
            HR_value2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("components") as Brush, Value = refval.HR_Value.max });
            HR_value2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("under") as Brush, Value = maximum });

            minimum = (int)(refval.BloodGlucose.min * 0.7);
            maximum = (int)(refval.BloodGlucose.max * 1.3);
            sugar2.Minimum = minimum;
            sugar2.Maximum = maximum;
            sugar2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("actual") as Brush, Value = refval.BloodGlucose.min });
            sugar2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("components") as Brush, Value = refval.BloodGlucose.max });
            sugar2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("under") as Brush, Value = maximum });

            minimum = (int)(refval.OxygenSaturation.min * 0.7);
            maximum = (int)(refval.OxygenSaturation.max * 1.3);
            SpO2_value2.Minimum = minimum;
            SpO2_value2.Maximum = maximum;
            SpO2_value2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("actual") as Brush, Value = refval.OxygenSaturation.min });
            SpO2_value2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("components") as Brush, Value = refval.OxygenSaturation.max });
            SpO2_value2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("under") as Brush, Value = maximum });

            minimum = (int)(refval.Pulse.min * 0.7);
            maximum = (int)(refval.Pulse.max * 1.3);
            Pulse2.Minimum = minimum;
            Pulse2.Maximum = maximum;
            Pulse2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("actual") as Brush, Value = refval.Pulse.min });
            Pulse2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("components") as Brush, Value = refval.Pulse.max });
            Pulse2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("under") as Brush, Value = maximum });

            minimum = (int)(refval.BodyTemperature.min * 0.7);
            maximum = (int)(refval.BodyTemperature.max * 1.3);
            temp2.Minimum = minimum;
            temp2.Maximum = maximum;
            temp2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("actual") as Brush, Value = refval.BodyTemperature.min });
            temp2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("components") as Brush, Value = refval.BodyTemperature.max });
            temp2.QualitativeRanges.Add(new QualitativeRange() { Brush = Application.Current.FindResource("under") as Brush, Value = maximum });

            #endregion

        }

        private void initMeasureType()
        {
            MeasureConditionServices service = new MeasureConditionServices();
            var list = service.Find(c => 1 == 1);
            list.Insert(0, new MeasureCondition { Id = "0", name = "测量条件" });
            comboPressure.ItemsSource = list;
            comboPressure.SelectedIndex = 0;

            comboGlucose.ItemsSource = list;
            comboGlucose.SelectedIndex = 0;

            comboOxygen.ItemsSource = list;
            comboOxygen.SelectedIndex = 0;

            comboTemp.ItemsSource = list;
            comboTemp.SelectedIndex = 0;

            comboEcg.ItemsSource = list;
            comboEcg.SelectedIndex = 0;
        }

        Thread t;
        bool isExit;
        void MeterPanel_Loaded(object sender, RoutedEventArgs e)
        {
            //t = new Thread(new ThreadStart(tick));
            //isExit = false;
            //t.Start();
        }

        void MeterPanel_Unloaded(object sender, RoutedEventArgs e)
        {
            selectedType = MeasureCategory.NotSelected;
            //isExit = true;
            //if (t != null)
            //    t.Join();
        }

        //void tick()
        //{
        //    Random rand = new Random();
        //    while (!isExit)
        //    {
        //        MeasureValue value = new MeasureValue();
        //        value.DBP = rand.Next(100);
        //        value.SBP = rand.Next(100);
        //        value.Map = rand.Next(100);
        //        value.NIBP = rand.Next(100);
        //        value.HR_Value = rand.Next(100);
        //        value.Pulse = rand.Next(100);
        //        value.Glucose = rand.Next(100);
        //        value.Temperature = rand.Next(100);
        //        value.SpO2_value = rand.Next(100);
        //        value.PressurePulse = rand.Next(100);


        //        value.ECG = new List<int>();
        //        value.SpO2 = new List<int>();

        //        for (int i = 0; i < 60; i++)
        //        {
        //            value.SpO2.Add(rand.Next(refval.OxygenSaturation.min, refval.OxygenSaturation.max));
        //        }
        //        for (int i = 0; i < 250; i++)
        //        {
        //            value.ECG.Add(rand.Next(refval.ECG.min, refval.ECG.max));
        //        }
        //        MeasureEventArgs e = new MeasureEventArgs(value);
        //        onMeasure(this, e);
        //        Thread.Sleep(1000);
        //    }

        //}

        public string id { get; set; }

        private void viewInfo_Click(object sender, RoutedEventArgs e)
        {
            UserForm win = new UserForm((appearance.DataContext as UserModel).UserId,false);
            win.ShowDialog();
        }

        //测量
        private MeasureCategory selectedType = MeasureCategory.NotSelected;

        public override void onMeasure(object sender, MeasureEventArgs e)
        {
            //Random r=new Random();
            //e.value.Glucose = r.Next(100);


            if (selectedType == MeasureCategory.NotSelected)
                return;

            if (selectedType == MeasureCategory.BloodPressure)
            {
                //收缩压
                if (e.value.SBP != 0)
                {
                    Action<Double> a = c => { SBP.Text = c.ToString(); SBP2.FeaturedMeasure = c; btnSavePressure.IsEnabled = true; };

                    Dispatcher.Invoke(a, Convert.ToDouble(e.value.SBP));
                }
                //舒张压
                if (e.value.DBP != 0)
                {
                    Action<Double> a = c => { DBP.Text = c.ToString(); DBP2.FeaturedMeasure = c; btnSavePressure.IsEnabled = true; };

                    Dispatcher.Invoke(a, Convert.ToDouble(e.value.DBP));
                }
                //脉率
                if (e.value.PressurePulse != 0)
                {
                    Action<Double> a = c => { HR_value.Text = c.ToString(); HR_value2.FeaturedMeasure = c; btnSavePressure.IsEnabled = true; };

                    Dispatcher.Invoke(a, Convert.ToDouble(e.value.PressurePulse));
                }
                //平均动脉压
                if (e.value.Map != 0)
                {
                    Action<int> a = c => { MAP.Text = c.ToString(); btnSavePressure.IsEnabled = true; };
                    Dispatcher.Invoke(a, e.value.Map);
                }

                int diff = e.value.SBP - e.value.DBP;
                //脉压差
                if (diff != 0)
                {
                    Action<int> a = c => { DIFF.Text = c.ToString(); btnSavePressure.IsEnabled = true; };
                    Dispatcher.Invoke(a, diff);
                }
            }

            if (selectedType == MeasureCategory.BloodGlucose)
            {
                if (e.value.Glucose != 0)
                {
                    Action<float> a = c => { sugar1.Text = c.ToString(); sugar2.FeaturedMeasure = c; btnSaveGlucose.IsEnabled = true; };
                    Dispatcher.Invoke(a, e.value.Glucose);
                }

            }

            if (selectedType == MeasureCategory.OxygenSaturation)
            {

                Dispatcher.Invoke(new Action<MeasureEventArgs>(OxyBind), e);
                
            }

            if (selectedType == MeasureCategory.BodyTemperature)
            {
                if (e.value.Temperature != 0)
                {
                    Action<double> a = c => { temp1.Text = c.ToString(); temp2.FeaturedMeasure = c; btnSaveTemp.IsEnabled = true; };
                    double format = double.Parse(e.value.Temperature.ToString("F1"));
                    Dispatcher.Invoke(a, format);

                }
            }

            if (selectedType == MeasureCategory.ECG)
            {
                Dispatcher.Invoke(new Action<MeasureEventArgs>(EcgBind), e);

            }


        }

        #region 血氧生成
        ChartModel oxyModel;
        private List<int> oxyValues;
        private void OxyBind(MeasureEventArgs e)
        {
            //血氧饱和度
            if (e.value.SpO2_value != 0)
            {
                SpO2_value.Text = e.value.SpO2_value.ToString();
                SpO2_value2.FeaturedMeasure = e.value.SpO2_value; 
                btnSaveOxygen.IsEnabled = true; 
            }

            //心率
            if (e.value.Pulse != 0
                //136 异常值
                && e.value.Pulse < 130)
            {
                Pulse.Text = e.value.Pulse.ToString();
                Pulse2.FeaturedMeasure = e.value.Pulse; 
                btnSaveOxygen.IsEnabled = true; 
            }

            if (e.value.SpO2 == null)
                return;
            
            //如果全部为0直接return
            bool isAllZero = true;
            for (int i = 0; i < e.value.SpO2.Count; i++)
            {
                if (e.value.SpO2[i] != 0)
                {
                    isAllZero = false;
                    break;
                }
            }
            if (isAllZero)
                return;


            oxyValues.AddRange(e.value.SpO2);
            DateTime now = DateTime.Now;
            oxyModel.EnqueueValue(e.value.SpO2, now);
            oxyModel.SetUpAxisXRange(now);

            oxyModel.Data = null;
            oxyModel.Data = oxyModel.CpuData;

        }
        #endregion

        #region 心电图生成
        ChartModel ecgModel;
        private List<int> ecgValues;
        private void EcgBind(MeasureEventArgs e)
        {
            if (e.value.ECG == null)
                return;
            //如果全部为0直接return
            bool isAllZero = true;
            for (int i = 0; i < e.value.ECG.Count; i++)
            {
                if (e.value.ECG[i] != 0)
                {
                    isAllZero = false;
                    break;
                }
            }
            if (isAllZero)
                return;

            btnSaveECG.IsEnabled = true;
            ecgValues.AddRange(e.value.ECG);
            DateTime now = DateTime.Now;
            ecgModel.EnqueueValue(e.value.ECG, now);
            ecgModel.SetUpAxisXRange(now);

            ecgModel.Data = null;
            ecgModel.Data = ecgModel.CpuData;
        }
        #endregion

        #region 界面控制
        private void enableLeftBtns(bool isEnabled)
        {
            btnPressure.IsEnabled = isEnabled;
            btnGlucose.IsEnabled = isEnabled;
            btnOxygen.IsEnabled = isEnabled;
            btnTemp.IsEnabled = isEnabled;
            btnECG.IsEnabled = isEnabled;
            btnComment.IsEnabled = isEnabled;
        }

        private void opaciteGrid(bool isMeasured)
        {
            float value = 0;
            if (isMeasured)
                value = 1;
            else
                value = 0.4F;

            gridPressure.Opacity = value;
            gridGlucose.Opacity = value;
            gridOxygen.Opacity = value;
            gridTemp.Opacity = value;
            gridChart.Opacity = value;
        }
        #endregion

        #region 左边按键事件

        private void btnPressure_Click(object sender, RoutedEventArgs e)
        {
            selectedType = MeasureCategory.BloodPressure;

            enableLeftBtns(false);
            opaciteGrid(false);
            gridPressure.Opacity = 1;
            
            comboPressure.Visibility = Visibility.Visible;
            btnSavePressure.Visibility = Visibility.Visible;
            btnSavePressure.IsEnabled = false;
            btnCancelPressure.Visibility = Visibility.Visible;
        }

        private void btnGlucose_Click(object sender, RoutedEventArgs e)
        {
            selectedType = MeasureCategory.BloodGlucose;

            enableLeftBtns(false);
            opaciteGrid(false);
            gridGlucose.Opacity = 1;

            comboGlucose.Visibility = Visibility.Visible;
            btnSaveGlucose.Visibility = Visibility.Visible;
            btnSaveGlucose.IsEnabled = false;
            btnCancelGlucose.Visibility = Visibility.Visible;
        }

        private void btnOxygen_Click(object sender, RoutedEventArgs e)
        {
            oxyValues = new List<int>();
            oxyModel = new ChartModel(60);
            oxyModel.AxisYMaxValue = (int)(refval.OxygenSaturation.max * 1.3);
            oxyModel.AxisYMinValue = (int)(refval.OxygenSaturation.min * 0.7);
            oxyModel.AxisYMinValue = oxyModel.AxisYMinValue / 10 * 10;
            oxyModel.AxisYStep = 20;
            oxyModel.YIntercept = Convert.ToInt32((refval.OxygenSaturation.max + refval.OxygenSaturation.min) / 2);
            borderChart.DataContext = oxyModel;
            RadChart1.SamplingSettings.SamplingThreshold = oxyModel.SamplingThreshold;


            selectedType = MeasureCategory.OxygenSaturation;

            enableLeftBtns(false);
            opaciteGrid(false);
            gridOxygen.Opacity = 1;
            gridChart.Opacity = 1;

            comboOxygen.Visibility = Visibility.Visible;
            btnSaveOxygen.Visibility = Visibility.Visible;
            btnSaveOxygen.IsEnabled = false;
            btnCancelOxygen.Visibility = Visibility.Visible;
        }

        private void btnTemp_Click(object sender, RoutedEventArgs e)
        {
            selectedType = MeasureCategory.BodyTemperature;

            enableLeftBtns(false);
            opaciteGrid(false);
            gridTemp.Opacity = 1;

            comboTemp.Visibility = Visibility.Visible;
            btnSaveTemp.Visibility = Visibility.Visible;
            btnSaveTemp.IsEnabled = false;
            btnCancelTemp.Visibility = Visibility.Visible;
        }

        private void btnECG_Click(object sender, RoutedEventArgs e)
        {
            ecgValues = new List<int>();
            ecgModel = new ChartModel(250);
            ecgModel.AxisYMaxValue = (int)(refval.ECG.max * 1.3);
            ecgModel.AxisYMinValue = (int)(refval.ECG.min * 0.7);
            ecgModel.AxisYMinValue = ecgModel.AxisYMinValue / 10 * 10;
            ecgModel.AxisYStep = 20;
            ecgModel.YIntercept = Convert.ToInt32((refval.ECG.max + refval.ECG.min) / 2);
            borderChart.DataContext = ecgModel;
            RadChart1.SamplingSettings.SamplingThreshold = ecgModel.SamplingThreshold;

            selectedType = MeasureCategory.ECG;

            enableLeftBtns(false);
            opaciteGrid(false);
            gridChart.Opacity = 1;

            comboEcg.Visibility = Visibility.Visible;
            btnSaveECG.Visibility = Visibility.Visible;
            btnSaveECG.IsEnabled = false; btnSavePressure.IsEnabled = false;
            btnCancelECG.Visibility = Visibility.Visible;

            
        }

        private void btnComment_Click(object sender, RoutedEventArgs e)
        {
            RadWindow win = new RadWindow();
            win.ShowDialog();
        }

        private void btnChange_Click(object sender, RoutedEventArgs e)
        {
            CardLogin win = new CardLogin((Application.Current.MainWindow as MainWindow).ContentFrame);
            win.ShowDialog();
        }

        #endregion

        #region 每个测试类型的保存事件


        private void btnSavePressure_Click(object sender, RoutedEventArgs e)
        {
            if (comboPressure.SelectedIndex == 0)
            {
                Tools.ShowMessage(true, "请选择测量条件！");
                return;
            }

            selectedType = MeasureCategory.NotSelected;

            int sbp, dbp, pulse, map, pp;
            int.TryParse(SBP.Text, out sbp);
            int.TryParse(DBP.Text, out dbp);
            int.TryParse(HR_value.Text, out pulse);
            int.TryParse(MAP.Text, out map);
            int.TryParse(DIFF.Text, out pp);

            BloodPressureService ser = new BloodPressureService();
            BloodPressure obj = new BloodPressure()
            {
                id = Guid.NewGuid().ToString(),
                measureUserId = (appearance.DataContext as UserModel).UserId,
                measureTime = DateTime.Now,
                SBP = sbp,
                DBP = dbp,
                Pulse = pulse,
                MAP = map,
                PP = pp,
                measureConditionCode = (comboPressure.SelectedItem as MeasureCondition).Id.ToString()
            };
            ser.Add(obj);

            comboPressure.Visibility = Visibility.Hidden;
            btnSavePressure.Visibility = Visibility.Hidden;
            btnCancelPressure.Visibility = Visibility.Hidden;
            enableLeftBtns(true);
            opaciteGrid(true);
        }



        private void btnSaveGlucose_Click(object sender, RoutedEventArgs e)
        {
            if (comboGlucose.SelectedIndex == 0)
            {
                Tools.ShowMessage(true, "请选择测量条件！");
                return;
            }

            selectedType = MeasureCategory.NotSelected;

            float sugar;
            float.TryParse(sugar1.Text, out sugar);

            BloodSugarService sugarSer = new BloodSugarService();
            BloodSugar obj = new BloodSugar()
            {
                id = Guid.NewGuid().ToString(),
                measureUserId = (appearance.DataContext as UserModel).UserId,
                measureTime = DateTime.Now,
                sugarValue = sugar,
                measureConditionCode = (comboGlucose.SelectedItem as MeasureCondition).Id.ToString()
            };
            sugarSer.Add(obj);

            comboGlucose.Visibility = Visibility.Hidden;
            btnSaveGlucose.Visibility = Visibility.Hidden;
            btnCancelGlucose.Visibility = Visibility.Hidden;
            enableLeftBtns(true);
            opaciteGrid(true);
        }

       

        private void btnSaveOxygen_Click(object sender, RoutedEventArgs e)
        {
            if (comboOxygen.SelectedIndex == 0)
            {
                Tools.ShowMessage(true, "请选择测量条件！");
                return;
            }

            selectedType = MeasureCategory.NotSelected;

            int oxy ;
            int.TryParse(SpO2_value.Text, out oxy);

            BloodOxygenService oxySer = new BloodOxygenService();
            BloodOxygen obj = new BloodOxygen()
            {
                id = Guid.NewGuid().ToString(),
                measureUserId = (appearance.DataContext as UserModel).UserId,
                measureTime = DateTime.Now,
                oxValue = oxy,
                Pulse = Pulse.Text.Trim() == null ? "0" : Pulse.Text.Trim(),
                measureConditionCode = (comboOxygen.SelectedItem as MeasureCondition).Id.ToString()
            };
            oxySer.Add(obj);


            //borderChart.DataContext = null;

            comboOxygen.Visibility = Visibility.Hidden;
            btnSaveOxygen.Visibility = Visibility.Hidden;
            btnCancelOxygen.Visibility = Visibility.Hidden;

            enableLeftBtns(true);
            opaciteGrid(true);
        }

        private void btnSaveTemp_Click(object sender, RoutedEventArgs e)
        {
            if (comboTemp.SelectedIndex == 0)
            {
                Tools.ShowMessage(true, "请选择测量条件！");
                return;
            }

            selectedType = MeasureCategory.NotSelected;

            BodyTemperatureService ser = new BodyTemperatureService();
            BodyTemperature obj = new BodyTemperature()
            {
                id = Guid.NewGuid().ToString(),
                measureUserId = (appearance.DataContext as UserModel).UserId,
                measureTime = DateTime.Now,
                tempValue = (float)(temp2.FeaturedMeasure),
                measureConditionCode = (comboTemp.SelectedItem as MeasureCondition).Id.ToString()
            };
            ser.Add(obj);


            comboTemp.Visibility = Visibility.Hidden;
            btnSaveTemp.Visibility = Visibility.Hidden;
            btnCancelTemp.Visibility = Visibility.Hidden;

            enableLeftBtns(true);
            opaciteGrid(true);
        }

        private void btnSaveECG_Click(object sender, RoutedEventArgs e)
        {
            if (comboEcg.SelectedIndex == 0)
            {
                Tools.ShowMessage(true, "请选择测量条件！");
                return;
            }

            selectedType = MeasureCategory.NotSelected;

            EcgService ser = new EcgService();
            ECG obj = new ECG()
               {
                   id = Guid.NewGuid().ToString(),
                   measureUserId = (appearance.DataContext as UserModel).UserId,
                   measureTime = DateTime.Now,
                   measureConditionCode = (comboEcg.SelectedItem as MeasureCondition).Id.ToString()
               };
            List<byte> temp = new List<byte>();
            foreach (int i in ecgValues)
            {
                temp.AddRange(BitConverter.GetBytes(i));
            }
            obj.EcgValues = temp.ToArray();
            ser.Add(obj);

            //borderChart.DataContext = null;

            comboEcg.Visibility = Visibility.Hidden;
            btnSaveECG.Visibility = Visibility.Hidden;
            btnCancelECG.Visibility = Visibility.Hidden;
            enableLeftBtns(true);
            opaciteGrid(true);
        }

        #endregion

        #region 每个测试类型的取消事件

        private void btnCancelPressure_Click(object sender, RoutedEventArgs e)
        {
            selectedType = MeasureCategory.NotSelected;

            comboPressure.Visibility = Visibility.Hidden;
            btnSavePressure.Visibility = Visibility.Hidden;
            btnCancelPressure.Visibility = Visibility.Hidden;
            enableLeftBtns(true);
            opaciteGrid(true);
        }

        private void btnCancelGlucose_Click(object sender, RoutedEventArgs e)
        {
            selectedType = MeasureCategory.NotSelected;

            comboGlucose.Visibility = Visibility.Hidden;
            btnSaveGlucose.Visibility = Visibility.Hidden;
            btnCancelGlucose.Visibility = Visibility.Hidden;
            enableLeftBtns(true);
            opaciteGrid(true);
        }

        private void btnCancelOxygen_Click(object sender, RoutedEventArgs e)
        {
            selectedType = MeasureCategory.NotSelected;

            comboOxygen.Visibility = Visibility.Hidden;
            btnSaveOxygen.Visibility = Visibility.Hidden;
            btnCancelOxygen.Visibility = Visibility.Hidden;

            enableLeftBtns(true);
            opaciteGrid(true);
        }

        private void btnCancelTemp_Click(object sender, RoutedEventArgs e)
        {
            selectedType = MeasureCategory.NotSelected;

            comboTemp.Visibility = Visibility.Hidden;
            btnSaveTemp.Visibility = Visibility.Hidden;
            btnCancelTemp.Visibility = Visibility.Hidden;

            enableLeftBtns(true);
            opaciteGrid(true);
        }

        private void btnCancelECG_Click(object sender, RoutedEventArgs e)
        {
            selectedType = MeasureCategory.NotSelected;

            comboEcg.Visibility = Visibility.Hidden;
            btnSaveECG.Visibility = Visibility.Hidden;
            btnCancelECG.Visibility = Visibility.Hidden;
            enableLeftBtns(true);
            opaciteGrid(true);
        }
        #endregion

 

    }
}
